## Cyclic normalized generating and control matrices

from PyM import *


def cyclic_normalized_matrix(g,n):
    x = variable(g); k = n-degree(g)
    G = []
    for j in range(k):
        r = - x**(n-k+j) % g
        r = coeffs_inc(r)
        r = pad(r,n-k)
        G += [r]
    return splice(matrix(G),I_(k,Z_))

def cyclic_normalized_control_matrix(g,n):
    G = cyclic_normalized_matrix(g,n)
    R = G[:,list(range(degree(g)))]
    return splice(I_(degree(g),Z_),transpose(-R))
    
K = Z_
[Kx,x] = polynomial_ring(K,'x', name = 'K[x]')

g = 1+2*x+x**3; n = 7

G = cyclic_normalized_matrix(g,n)
H = cyclic_normalized_control_matrix(g,n)

show(G)

show(H)